import 'package:flutter/material.dart';
import 'package:hi_barrage/barrage_transition.dart';

// 弹幕widget
// ignore: must_be_immutable
class BarrageItem extends StatelessWidget {
  final String id;
  final double top;
  final Widget child; //弹幕里具体显示的内容
  final ValueChanged onComplete; //是否播放完成
  final Duration duration; //从右到左播放的时间
  BarrageItem({
    Key key,
    this.id,
    this.top,
    this.child,
    this.onComplete,
    this.duration = const Duration(milliseconds: 9000),
  }) : super(key: key);
  // fix动画状态错乱
  var _key = GlobalKey<BarrageTransitionState>();

  @override
  Widget build(BuildContext context) {
    return Positioned.fill(
        top: top,
        child: BarrageTransition(
          key: _key,
          child: child,
          onComplete: (v) {
            onComplete(id);
          },
          duration: duration,
        ));
  }
}
